﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Collections.Generic;

namespace AIC_CS
{
    public partial class phuluc7 : MyUserBase
    {
        private string BaoCaoNumbert;
        private string Donvi_id;
        private string ky_baocao;
        protected void Page_Load(object sender, EventArgs e)
        {
            BaoCaoNumbert = Session["ReportNumber"].ToString();
            Donvi_id = MyCommon.GetDonViID(Session["userid"].ToString());
            ky_baocao = Session["ReportPeriod"].ToString();
            if (Session["SwitchCase"].ToString() != "Null")
            {
                BinDataToControls();
                if (Session["SwitchCase"].ToString() == "Detail")
                    btnLuuPL7.Enabled = false;
                else
                    if (Session["SwitchCase"].ToString() == "Sua")
                    {
                        btnLuuPL7.CommandName = "CapNhat";
                        btnLuuPL7.Enabled = true;
                    }
            }
        }
        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("phuluc7_update.aspx");
        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

        }

        protected void btnLuuPL7_Click(object sender, EventArgs e)
        {
            #region param
            BaoCaoNumbert = Session["ReportNumber"].ToString();
            Donvi_id = MyCommon.GetDonViID(Session["userid"].ToString());
            ky_baocao = Session["ReportPeriod"].ToString();
            int RecordID = Convert.ToInt32(Session["ReportID"]);
            List<SqlParameter> lstParameter = new List<SqlParameter>();
            lstParameter.Add(SqlHelper.CreateParameterObject("@KyBaoCaoID_DM", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(ky_baocao)));
            lstParameter.Add(SqlHelper.CreateParameterObject("@DonVi_ID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(Donvi_id)));
            lstParameter.Add(SqlHelper.CreateParameterObject("@BaoCaoSo", SqlDbType.NVarChar, ParameterDirection.Input, txtF1.Text.Trim()));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F1", SqlDbType.NVarChar, ParameterDirection.Input, txtF1.Text.Trim()));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F2", SqlDbType.Float, ParameterDirection.Input, txtF2.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF2.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F3", SqlDbType.Float, ParameterDirection.Input, txtF3.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF3.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F4", SqlDbType.Float, ParameterDirection.Input, txtF4.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF4.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F5", SqlDbType.Float, ParameterDirection.Input, txtF5.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF5.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F6", SqlDbType.Float, ParameterDirection.Input, txtF6.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF6.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F7", SqlDbType.Float, ParameterDirection.Input, txtF7.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF7.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F8", SqlDbType.Float, ParameterDirection.Input, txtF8.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF8.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F9", SqlDbType.Float, ParameterDirection.Input, txtF9.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF9.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F10", SqlDbType.Float, ParameterDirection.Input, txtF10.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF10.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F11", SqlDbType.Float, ParameterDirection.Input, txtF11.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF11.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F12", SqlDbType.Float, ParameterDirection.Input, txtF12.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF12.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F13", SqlDbType.Float, ParameterDirection.Input, txtF13.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF13.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F14", SqlDbType.Float, ParameterDirection.Input, txtF14.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF14.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F15", SqlDbType.Float, ParameterDirection.Input, txtF15.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF15.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F16", SqlDbType.Float, ParameterDirection.Input, txtF16.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF16.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F17", SqlDbType.Float, ParameterDirection.Input, txtF17.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF17.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F18", SqlDbType.Float, ParameterDirection.Input, txtF18.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF18.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F19", SqlDbType.Float, ParameterDirection.Input, txtF19.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF19.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F20", SqlDbType.Float, ParameterDirection.Input, txtF20.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF20.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F21", SqlDbType.Float, ParameterDirection.Input, txtF21.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF21.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F22", SqlDbType.Float, ParameterDirection.Input, txtF22.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF22.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F23", SqlDbType.Float, ParameterDirection.Input, txtF23.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF23.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F24", SqlDbType.Float, ParameterDirection.Input, txtF24.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF24.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F25", SqlDbType.Float, ParameterDirection.Input, txtF25.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF25.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F26", SqlDbType.Float, ParameterDirection.Input, txtF26.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF26.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F27", SqlDbType.Float, ParameterDirection.Input, txtF27.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF27.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F28", SqlDbType.Float, ParameterDirection.Input, txtF28.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF28.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F29", SqlDbType.Float, ParameterDirection.Input, txtF29.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF29.Text.Trim())));

            lstParameter.Add(SqlHelper.CreateParameterObject("@F30", SqlDbType.Float, ParameterDirection.Input, txtF30.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF30.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F31", SqlDbType.Float, ParameterDirection.Input, txtF31.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF31.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F32", SqlDbType.Float, ParameterDirection.Input, txtF32.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF32.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F33", SqlDbType.Float, ParameterDirection.Input, txtF33.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF33.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F34", SqlDbType.Float, ParameterDirection.Input, txtF34.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF34.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F35", SqlDbType.Float, ParameterDirection.Input, txtF35.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF35.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F36", SqlDbType.Float, ParameterDirection.Input, txtF36.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF36.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@F37", SqlDbType.Float, ParameterDirection.Input, txtF37.Text.Trim().Equals("") ? 0 : Convert.ToDouble(txtF37.Text.Trim())));
            lstParameter.Add(SqlHelper.CreateParameterObject("@UserID", SqlDbType.Int, ParameterDirection.Input, Convert.ToInt32(Session["userid"])));
            #endregion param
            string sSQL = "";
            if (btnLuuPL7.CommandName.Equals("CapNhat"))
            {
                lstParameter.Add(SqlHelper.CreateParameterObject("@ID", SqlDbType.Int, ParameterDirection.Input, RecordID));
                sSQL = "UPDATE dbo.tblPhuLuc7 SET BaoCaoSo=@BaoCaoSo,F1=@F1,F2=@F2,F3=@F3,F4=@F4,F5=@F5,F6=@F6,F7=@F7,F8=@F8,F9=@F9,F10=@F10,F11=@F11,F12=@F12,F13=@F13," +
                            "F14=@F14,F15=@F15,F16=@F16,F17=@F17,F18=@F18,F19=@F19,F20=@F20,F21=@F21,F22=@F22,F23=@F23,F24=@F24,F25=@F25,F26=@F26,F27=@F27,F28=@F28,F29=@F29," +
                            "F30=@F30,F31=@F31,F32=@F32,F33=@F33,F34=@F34,F35=@F35,F36=@F36,F37=@F37,UpdateDate=GETDATE(),UserID=@UserID WHERE ID=@ID";
            }
            else
            {
                sSQL = "INSERT INTO  dbo . tblPhuLuc7( KyBaoCaoID_DM , DonVi_ID , BaoCaoSo , F1 , F2 , F3 , F4 ,F5 , F6 , F7 , F8 , F9 " +
                        ", F10 , F11 , F12 , F13 , F14 , F15 , F16 , F17 , F18 , F19 , F20 , F21 , F22 , F23 , F24 , F25 , F26 , F27 , F28 , F29 , F30 , F31 , F32 , F33 , F34 , F35 , F36 , F37 , CreateDate , UpdateDate , UserID )" +
                         "VALUES (@KyBaoCaoID_DM,@DonVi_ID,@BaoCaoSo,@F1,@F2,@F3,@F4,@F5,@F6,@F7,@F8,@F9,@F10,@F11,@F12,@F13,@F14,@F15,@F16,@F17,@F18,@F19,@F20,@F21,@F22,@F23,@F24,@F25,@F26,@F27,@F28,@F29,@F30,@F31,@F32,@F33,@F34,@F35,@F36,@F37,GETDATE(),GETDATE(),@UserID )";
            }
            SqlHelper.ExecuteNonQuery(CommandType.Text, sSQL, lstParameter);
            Response.Redirect("phuluc7_update.aspx");
        }
        protected void BinDataToControls()
        {
            string sql = "SELECT a.ID ,a.KyBaoCaoID_DM ,a.DonVi_ID ,a.BaoCaoSo ,a.F1  ,a.F2 ,a.F3  ,a.F4, a.F5 ,a.F6 ,a.F7 ,a.F8 ,a.F9 ,a.F10 ,a.F11 ,a.F12 ,a.F13 ,a.F14" +
      ",a.F15 ,a.F16 ,a.F17 ,a.F18 ,a.F19 ,a.F20 ,a.F21 ,a.F22 ,a.F23 ,a.F24 ,a.F25 ,a.F26 ,a.F27 ,a.F28 ,a.F29,a.F30 ,a.F31 ,a.F32 ,a.F33 ,a.F34 ,a.F35 ,a.F36 ,a.F37 " +
      " FROM tblPhuLuc7 a" +
      " where a.id='" + Session["ReportID"] + "'";
            SqlDataReader myReader = SqlHelper.ExecuteReader(CommandType.Text, sql);
            myReader.Read();
            txtF1.Text = myReader["F1"].ToString();
            txtF2.Text = myReader["F2"].ToString();
            txtF3.Text = myReader["F3"].ToString();
            txtF4.Text = myReader["F4"].ToString();
            txtF5.Text = myReader["F5"].ToString();
            txtF6.Text = myReader["F6"].ToString();
            txtF7.Text = myReader["F7"].ToString();
            txtF8.Text = myReader["F8"].ToString();
            txtF9.Text = myReader["F9"].ToString();
            txtF10.Text = myReader["F10"].ToString();
            txtF11.Text = myReader["F11"].ToString();
            txtF12.Text = myReader["F12"].ToString();
            txtF13.Text = myReader["F13"].ToString();
            txtF14.Text = myReader["F14"].ToString();
            txtF15.Text = myReader["F15"].ToString();
            txtF16.Text = myReader["F16"].ToString();
            txtF17.Text = myReader["F17"].ToString();
            txtF18.Text = myReader["F18"].ToString();
            txtF19.Text = myReader["F19"].ToString();
            txtF20.Text = myReader["F20"].ToString();
            txtF21.Text = myReader["F21"].ToString();
            txtF22.Text = myReader["F22"].ToString();
            txtF23.Text = myReader["F23"].ToString();
            txtF24.Text = myReader["F24"].ToString();
            txtF25.Text = myReader["F25"].ToString();
            txtF26.Text = myReader["F26"].ToString();
            txtF27.Text = myReader["F27"].ToString();
            txtF28.Text = myReader["F28"].ToString();
            txtF29.Text = myReader["F29"].ToString();
            txtF30.Text = myReader["F30"].ToString();
            txtF31.Text = myReader["F31"].ToString();
            txtF32.Text = myReader["F32"].ToString();
            txtF33.Text = myReader["F33"].ToString();
            txtF34.Text = myReader["F34"].ToString();
            txtF35.Text = myReader["F35"].ToString();
            txtF36.Text = myReader["F36"].ToString();
            txtF37.Text = myReader["F37"].ToString();
        }
    }
}